package com.powergisol.gis.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powergisol.gis.entity.TabVisual;
import com.powergisol.gis.service.TabVisualService;
import com.powergisol.gis.util.Result;
import com.powergisol.gis.vo.SearchVisualVo;
import com.powergisol.gis.vo.TabUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;


/**
 * Created By marc
 * Date: 2020/9/22  10:55
 * Description:视角
 */
@RestController
@RequestMapping(value = "visual")
@Api(description = "自定义视角" ,value = "自定义视角")
public class TabVisualController extends BaseController {

    @Autowired
    private TabVisualService tabVisualService;

    @RequestMapping(value = "getVisualList", method = RequestMethod.POST)
    @ApiOperation(value = "视角列表", notes = "视角列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "page", value = "页数", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "limit", value = "条数", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "scenceId", value = "场景id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getVisualList(Principal p, SearchVisualVo vo){
        Result result = new Result();
        TabUserVo tabUserVo = getUser(p);
        vo.setUserId(tabUserVo.getId());
        PageHelper.startPage(vo.getPage(), vo.getLimit());
        PageInfo<TabVisual> pageInfo = new PageInfo<>(tabVisualService.getVisualList(vo));
        result.setCount((int) pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    @RequestMapping(value = "getAcquiesce", method = RequestMethod.POST)
    @ApiOperation(value = "获取默认", notes = "获取默认")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "scenceId", value = "场景id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getAcquiesce(Integer scenceId){
        return tabVisualService.getAcquiesce(scenceId);
    }

    @RequestMapping(value = "setAcquiesce", method = RequestMethod.POST)
    @ApiOperation(value = "设置默认", notes = "设置默认")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "视角id", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "scenceId", value = "场景id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result setAcquiesce(Integer id,Integer scenceId){
        return tabVisualService.setAcquiesce(id,scenceId);
    }

    @RequestMapping(value = "delVisual", method = RequestMethod.POST)
    @ApiOperation(value = "删除视角", notes = "删除视角")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "视角id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result delVisual(Integer id){
        return tabVisualService.delVisual(id);
    }

    @RequestMapping(value = "visualDetail", method = RequestMethod.POST)
    @ApiOperation(value = "视角详情", notes = "视角详情")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "视角id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result visualDetail(Integer id){
        return tabVisualService.visualDetail(id);
    }

    @RequestMapping(value = "renameVisual", method = RequestMethod.POST)
    @ApiOperation(value = "重命名", notes = "重命名")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "viewName", value = "视角名称", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "视角id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result renameVisual(String viewName,Integer id){
        return tabVisualService.renameVisual(viewName,id);
    }

    @RequestMapping(value = "addVisual", method = RequestMethod.POST)
    @ApiOperation(value = "增加视角", notes = "增加视角")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "viewName", value = "视角名称", defaultValue = "0", required = true, paramType ="query"),
            @ApiImplicitParam(dataType = "Integer", name = "scenceId", value = "场景id", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "flyTime", value = "飞行时间", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "imgUrl", value = "缩略图", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "positionLat", value = "经度", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "positionLon", value = "纬度", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "positionH", value = "高度", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "heading", value = "", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "pitch", value = "", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Double", name = "roll", value = "", defaultValue = "0", required = true, paramType = "query"),
    })
    public Result addVisual(TabVisual visual,Principal p){
        TabUserVo tabUserVo = getUser(p);
        visual.setUserId(tabUserVo.getId());
        return tabVisualService.addVisual(visual);
    }

}
